package cn.com.twoke.game.client.handler;

import cn.com.twoke.game.client.cache.ClientCacheManager;
import cn.com.twoke.game.client.games.GameManager;
import cn.com.twoke.game.client.games.framework.core.Game;
import cn.com.twoke.game.common.entity.message.GameDataMessage;
import cn.com.twoke.game.common.handler.MessageHandler;

import java.io.IOException;
import java.nio.channels.Selector;
import java.nio.channels.SocketChannel;

public class GameDataMessageHandler implements MessageHandler<GameDataMessage> {

    @Override
    public void handle(Selector selector, SocketChannel channel, GameDataMessage message) throws IOException {
        String gameId = message.getGameId();
        Game game = ClientCacheManager.INSTANCE.getGame(gameId);
        if (game != null) {
            GameManager.GAME_DATA_HANDLER_MAP.get(gameId).handle(message);
        }
    }

}
